package jmine.tec.script.impl;

import org.apache.commons.lang.StringUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * @author jrenaut
 */
public class AScriptLoggerImplShould {

    private ScriptLoggerImpl logger;

    @Before
    public void before() {
        this.logger = new ScriptLoggerImpl();
    }

    @Test
    public void logInfo() {
        Assert.assertTrue(this.logger.getLogs().isEmpty());
        Assert.assertTrue(this.logger.isSuccess());
        this.logger.info("some info");
        Assert.assertFalse(this.logger.getLogs().isEmpty());
        Assert.assertEquals(this.logger.getLogs().get(0), "some info");
        Assert.assertTrue(this.logger.isSuccess());
    }

    @Test
    public void logTrace() {
        Assert.assertTrue(StringUtils.isEmpty(this.logger.getTraces()));
        Assert.assertTrue(this.logger.isSuccess());
        this.logger.trace("some trace");
        Assert.assertFalse(StringUtils.isEmpty(this.logger.getTraces()));
        Assert.assertEquals(this.logger.getTraces(), "some trace");
        Assert.assertTrue(this.logger.isSuccess());
    }

    @Test
    public void fail() {
        Assert.assertTrue(StringUtils.isEmpty(this.logger.getTraces()));
        Assert.assertTrue(this.logger.isSuccess());
        this.logger.fail("some failure");
        Assert.assertFalse(this.logger.getLogs().isEmpty());
        Assert.assertEquals(this.logger.getLogs().get(0), "some failure");
        Assert.assertFalse(this.logger.isSuccess());
    }

    @Test
    public void failWithException() {
        Assert.assertTrue(StringUtils.isEmpty(this.logger.getTraces()));
        Assert.assertTrue(this.logger.isSuccess());
        this.logger.fail("some failure", new Throwable("some message"));
        Assert.assertFalse(this.logger.getLogs().isEmpty());
        Assert.assertEquals(this.logger.getLogs().get(0), "some failure");
        Assert.assertEquals(this.logger.getLogs().get(1), "some message");
        Assert.assertFalse(this.logger.isSuccess());
    }

}
